--
-- DESCRIPTION
--
-- @COMPANY **
-- @AUTHOR **
-- @DATE ${date} ${time}
--

---@type BP_MyWidget_C
local M = UnLua.Class()

-- function M:Initialize(Initializer)
-- end

--function M:PreConstruct(IsDesignTime)
--end

-- 覆盖蓝图的 Event Construct
function M:Construct()
  -- 启动就播放一次动画
  self:PlayAnimation(self.NewAnimation, 0.0, 1, UE4.EUMGSequencePlayMode.Forward, 1.0)

  -- 调用蓝图函数Init
  self:Init()
  
  -- 绑定没生效
  -- self.NewAnimation.OnAnimationFinished:Add(self, function()
  --   print('NewAnimation started')
  --   self.TextBlock_Power:SetText('Lua Power Off')
  -- end)

  -- 绑定lua匿名函数
  -- 这里不会覆盖蓝图的 OnPressed
  self.Button_Power.OnPressed:Add(self, function()
    print('Button_Power pressed')
    -- self.TextBlock_Power:SetText('Lua Power On')
    self:PowerTriggered()

    -- 也可以直接调 Event
    -- self:CustomEvent_0()
  end)

  -- 绑定lua成员函数, 重复绑定的函数都会生效
  self.Button_Power.OnPressed:Add(self, self.PowerPressed)
end

--function M:Tick(MyGeometry, InDeltaTime)
--end

function M:PowerPressed()
  print('PowerPressed')
  self.TextBlock_Power:SetText('Lua Power On')

  local World = self:GetWorld()
  if not World then
    return
  end

  -- 动态加载Actor, 注意这里多一个后缀 _C
  local MyActorClass = UE4.UClass.Load("/Game/BP_MyActor.BP_MyActor_C")
  local MyTmpActor = World:SpawnActor(MyActorClass, UE.FVector(), UE4.ESpawnActorCollisionHandlingMethod.AlwaysSpawn, self, self, "")
  -- self.Actor = MyTmpActor
  print(MyTmpActor.SpecialName)
end

return M
